#include "stdafx.h"
#include "Mouse.h"

namespace Framework {

Mouse* Mouse::mouse = NULL;

Mouse::Mouse(void) {
    this->leftButton = BUTTONSTATE_RELEASED;
    this->middleButton = BUTTONSTATE_RELEASED;
    this->rightButton = BUTTONSTATE_RELEASED;
    this->x = 0;
    this->y = 0;
}

Mouse::~Mouse(void) {
}

ButtonState Mouse::GetLeftButton() const {
    return this->leftButton;
}

ButtonState Mouse::GetMiddleButton() const {
    return this->middleButton;
}

ButtonState Mouse::GetRightButton() const {
    return this->rightButton;
}

long Mouse::GetX() const {
    return this->x;
}

long Mouse::GetY() const {
    return this->y;
}

Mouse* Mouse::GetInstance() {
    if (Mouse::mouse == NULL) {
        Mouse::mouse = new Mouse();
    }

    return Mouse::mouse;
}

void Mouse::Update(RAWMOUSE raw) {
    Mouse::GetInstance()->x = raw.lLastX;
    Mouse::GetInstance()->y = raw.lLastY;
    if (raw.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN) {
        Mouse::GetInstance()->leftButton = BUTTONSTATE_PRESSED;
    } else if (raw.ulButtons & RI_MOUSE_LEFT_BUTTON_UP) {
        Mouse::GetInstance()->leftButton = BUTTONSTATE_RELEASED;
    }

    if (raw.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN) {
        Mouse::GetInstance()->middleButton = BUTTONSTATE_PRESSED;
    } else if (raw.ulButtons & RI_MOUSE_MIDDLE_BUTTON_UP) {
        Mouse::GetInstance()->middleButton = BUTTONSTATE_RELEASED;
    }

    if (raw.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN) {
        Mouse::GetInstance()->rightButton = BUTTONSTATE_PRESSED;
    } else if (raw.ulButtons & RI_MOUSE_RIGHT_BUTTON_UP) {
        Mouse::GetInstance()->rightButton = BUTTONSTATE_RELEASED;
    }
}

}
